package bg.btanev.eightyfour.domain.experience;

import org.apache.commons.lang.Validate;

import bg.btanev.eightyfour.domain.experience.institution.EducationInstitution;
import bg.btanev.eightyfour.domain.person.Person;

/**
 *
 * @author B.Tanev
 *
 */
public class EducationExperience extends Experience<EducationInstitution> {
	/**
	 *
	 */
	private static final long serialVersionUID = 8941013857608883071L;

	private String speciality;

	protected EducationExperience() {
		super();
	}

	public EducationExperience(ExperiencePeriod period, EducationInstitution institution, Person person,
			String speciality) {

		this(null, period, institution, person, speciality);
	}

	public EducationExperience(Long id, ExperiencePeriod period, EducationInstitution institution, Person person,
			String speciality) {

		super(id, period, institution, person);

		Validate.notEmpty(speciality, "Speciality cannot be empty.");
		this.speciality = speciality;
	}

	public String getSpeciality() {
		return speciality;
	}

	@Override
	protected Person updatePersonInternal(Person person) {
		Person oldPerson = getPerson();
		if (oldPerson != null) {
			oldPerson.removeEducationExperience(this);
		}
		person.addEducationExperience(this);

		return person;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((speciality == null) ? 0 : speciality.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		EducationExperience other = (EducationExperience) obj;
		if (speciality == null) {
			if (other.speciality != null)
				return false;
		} else if (!speciality.equals(other.speciality))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "EducationExperience [speciality=" + speciality + ", toString()=" + super.toString() + "]";
	}
}
